-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mini-Max Sum.c
38 lines (34 loc) · 876 Bytes
/
Mini-Max Sum.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @Repository HackerRank Soulutions
* @file Mini-Max Sum
* @author Abdelrahman Ahmed Moussa ([email protected])
* @copyright Copyright (c) 2024
*
*/
void miniMaxSum(int arr_count, int* arr)
{
unsigned long sum=0;
unsigned long min=arr[0]+arr[1]+arr[2]+arr[3]+arr[4]; // or unsigned long min=4000000000; the max value for unsigned long
unsigned long max=arr[0]; //or unsigned long max=0; the min value for unsigned long
int i=0,j=0;
for (i=0; i<arr_count ;i++ )
{
for (j=0;j<arr_count; j++)
{
if (i!=j)
{
sum=sum+arr[j];
}
}
if (sum>max)
{
max=sum;
}
if (sum<min)
{
min=sum;
}
sum=0;
}
printf("%ld %ld",min,max);
}